package edu.id.doublebrickbreaker;

import java.awt.Color;
import java.awt.event.KeyEvent;


public class BrickBreaken {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		StdDraw.setCanvasSize(500, 750);
		StdDraw.setXscale(0,500);
		StdDraw.setYscale(0,750);
		int lowerX = 250;
		int lowerY = 175;
		int upperX= 250;
		int upperY=575;
		double x2 = 250.0;
		double by = 375.0;
		double r = 4.0;
		double byspeed = 2;
		double bx = 250;
		double bxspeed = 2;



		/*StdDraw.setCanvasSize(600, 400);
		StdDraw.setXscale(0, 600);
		StdDraw.setYscale(0, 400);

		StdDraw.filledCircle(300, 200, 50);
		StdDraw.setPenColor(Color.CYAN);
		StdDraw.filledRectangle(300, 50, 50, 25);

		int x = 300;
		int y = 200;
		 */

		/*
        while (x < 500) {
                x += 50;
                StdDraw.clear();
                StdDraw.filledRectangle(x, y, 50, 25);
                StdDraw.show(500);
        }
		 */


		while (true) {
			if (StdDraw.isKeyPressed(KeyEvent.VK_A))
				lowerX -= 10;
			else if (StdDraw.isKeyPressed(KeyEvent.VK_D))
				lowerX += 10;

			if (StdDraw.isKeyPressed(KeyEvent.VK_LEFT))
				upperX -= 10;
			else if (StdDraw.isKeyPressed(KeyEvent.VK_RIGHT))
				upperX += 10;

			if (upperX>515)
			{
				upperX-=505;
			}
			if (upperX<-10)
			{
				upperX+=495;
			}
			if (lowerX>515)
			{
				lowerX-=505;
			}
			if (lowerX<-10)
			{
				lowerX+=495;
			}
			by-=byspeed;
			bx -=bxspeed;
			/* If the ball's x is greater than the paddle's left x and the ball's x is less than the paddle's right x */



			if (by+r<lowerY+5 && by+r>lowerY && bx>=lowerX-30 && bx<lowerX+30) 
			{
				if (Math.abs(lowerX)>10 && Math.abs(lowerX)<20)
				{
					bxspeed-=2.5;
				}
				else if (Math.abs(lowerX)<20 && Math.abs(lowerX)<25)
				{
					bxspeed-=2.7;
				}
				else if (Math.abs(lowerX)<25 && Math.abs (lowerX)<30)
				{
					bxspeed-=3;
				}
				else{
					byspeed =-2;
				}

			}
			if (by+r>lowerY-5 && by+r<lowerY && bx>=lowerX-30 && bx<lowerX+30) 
			{
				byspeed =2;

			}

			if (by-r>upperY-5 && by-r<upperY && bx<=upperX+30 && bx>=upperX-30)

			{
				byspeed =2;

			}
			if (by-r<upperY+5 && by>upperY && bx<=upperX+30 && bx>=upperX-30)

			{
				byspeed =-2;

			}
			if (bx<1 || bx>499)
			{
				bxspeed*=-1;
			}
			if (by<1 || by>749)
			{
				byspeed*=-1;
			}



			StdDraw.clear();
			StdDraw.filledRectangle(upperX, upperY, 30, 5);
			StdDraw.filledRectangle(lowerX, lowerY, 30, 5);
			StdDraw.filledCircle(bx, by, r);
			StdDraw.show(10);
		}


	}
}




